
//
//  YXPlayerBottomView.swift
//  swift_wobo
//
//  Created by yuxin on 2018/12/1.
//  Copyright © 2018 wuxiantianli. All rights reserved.
//

import UIKit

class YXPlayerBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let size = bounds.size
        totalLabel.sizeToFit()
        let padding: CGFloat = 5
        let labelW: CGFloat = totalLabel.frame.width+1
        
        currLabel.frame = CGRect.init(x: padding, y: 0, width: labelW, height: size.height)
        totalLabel.frame = CGRect.init(x: size.width-padding-labelW, y: 0, width: labelW, height: size.height)
        let progressW = (size.width-((2*padding + labelW)*2))
        bufferView.frame = CGRect.init(x: currLabel.frame.maxX+padding, y: 0, width: progressW, height: size.height)
        bufferView.center.y = currLabel.center.y
        
        progressView.frame = CGRect.init(x: currLabel.frame.maxX+padding-2, y: 0, width: progressW+2, height: size.height)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        
    }
    
    func setup() {
        addSubview(currLabel)
        addSubview(bufferView)
        addSubview(totalLabel)
        addSubview(progressView)
    }
    
    //MARK: - lazy
    lazy var currLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor.white
        l.font = UIFont.systemFont(ofSize: 18)
        l.text = "00:00"
        return l
    }()
    lazy var totalLabel: UILabel = {
        let l = UILabel()
        l.textColor = UIColor.white
        l.font = UIFont.systemFont(ofSize: 18)
        l.text = "00:00"
        return l
    }()
    lazy var bufferView: UIProgressView = {
       let p = UIProgressView()
        p.progressTintColor = UIColor.lightGray
        p.trackTintColor = UIColor.clear
        
        for item in p.subviews {
            if let imageView = item as? UIImageView {
                imageView.layer.cornerRadius = 2;
                imageView.clipsToBounds = true;
            }
        }
        return p
    }()
    lazy var progressView: UISlider = {
       let s = UISlider()
        s.thumbTintColor = UIColor.red
        s.setThumbImage(UIImage(named: "player_keai"), for: UIControl.State.normal)
        s.maximumTrackTintColor = UIColor.clear
        s.minimumTrackTintColor = UIColor.green
        
        return s
    }()
}
